package com.pica.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.pica.common.annotation.Log;
import com.pica.common.enums.BusinessType;
import com.pica.system.domain.Comments;
import com.pica.system.service.ICommentsService;
import com.pica.common.core.controller.BaseController;
import com.pica.common.core.domain.AjaxResult;
import com.pica.common.utils.poi.ExcelUtil;
import com.pica.common.core.page.TableDataInfo;

/**
 * commentsController
 * 
 * @author 徐鑫杰
 * @date 2022-12-14
 */
@Controller
@RequestMapping("/system/comments")
public class CommentsController extends BaseController
{
    private String prefix = "system/comments";

    @Autowired
    private ICommentsService commentsService;

    @RequiresPermissions("system:comments:view")
    @GetMapping()
    public String comments()
    {
        return prefix + "/comments";
    }

    /**
     * 查询comments列表
     */
    @RequiresPermissions("system:comments:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Comments comments)
    {
        startPage();
        List<Comments> list = commentsService.selectCommentsList(comments);
        return getDataTable(list);
    }

    /**
     * 导出comments列表
     */
    @RequiresPermissions("system:comments:export")
    @Log(title = "comments", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Comments comments)
    {
        List<Comments> list = commentsService.selectCommentsList(comments);
        ExcelUtil<Comments> util = new ExcelUtil<Comments>(Comments.class);
        return util.exportExcel(list, "comments数据");
    }

    /**
     * 新增comments
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存comments
     */
    @RequiresPermissions("system:comments:add")
    @Log(title = "comments", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Comments comments)
    {
        return toAjax(commentsService.insertComments(comments));
    }

    /**
     * 修改comments
     */
    @RequiresPermissions("system:comments:edit")
    @GetMapping("/edit/{comId}")
    public String edit(@PathVariable("comId") Long comId, ModelMap mmap)
    {
        Comments comments = commentsService.selectCommentsByComId(comId);
        mmap.put("comments", comments);
        return prefix + "/edit";
    }

    /**
     * 修改保存comments
     */
    @RequiresPermissions("system:comments:edit")
    @Log(title = "comments", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Comments comments)
    {
        return toAjax(commentsService.updateComments(comments));
    }

    /**
     * 删除comments
     */
    @RequiresPermissions("system:comments:remove")
    @Log(title = "comments", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(commentsService.deleteCommentsByComIds(ids));
    }
}
